package logic

import (
	"context"
	"gorm.io/gorm"
	"we-chat/models"

	"we-chat/userrpc/internal/svc"
	"we-chat/userrpc/userrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type AddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddLogic {
	return &AddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *AddLogic) Add(in *userrpc.AddRequest) (*userrpc.AddResponse, error) {
	// todo: add your logic here and delete this line
	user := models.User{
		Model:   gorm.Model{ID: uint(in.UserId)},
		Context: in.Context,
	}
	models.DB.Create(&user)
	return &userrpc.AddResponse{
		UserId: int64(user.ID),
	}, nil
}
